package com.suntront.module_login.main

import android.os.Message
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.mtjsoft.www.kotlinmvputils.base.BaseActivity
import com.mtjsoft.www.kotlinmvputils.constants.RouterConstants
import com.mtjsoft.www.kotlinmvputils.utils.AndActivityUtils
import com.suntront.module_login.R
import com.tencent.mmkv.MMKV
import kotlinx.android.synthetic.main.activity_main.*

/**
 * 主页
 * @author mtj
 * @Package com.suntront.module_login.main
 * @date 2020-05-26 09:11:28
 */
@Route(path = RouterConstants.MAIN_ACTIVITY)
class MainActivity : BaseActivity<MainViewModel>() {

    override fun layoutResId(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
        removeAllBaseTopLayout()
    }

    override fun initData() {
        main_tv_username.text = MMKV.defaultMMKV().decodeString("AdminName", "")
    }

    override fun providerVMClass(): Class<MainViewModel>? {
        return MainViewModel::class.java
    }

    override fun onClick(p0: View) {
        super.onClick(p0)
        when (p0.id) {
            R.id.main_title_bg -> {
                // 个人信息
                ARouter.getInstance().build(RouterConstants.MINE_ACTIVITY).navigation()
            }
            R.id.main_bottommenu_metertask -> {
                // 抄表任务
                ARouter.getInstance()
                    .build(RouterConstants.MeterTask_MeterList)
                    .withInt("type", 0)
                    .navigation()
            }
            R.id.main_midmenu_admindetail -> {
                // 抄表排序
                ARouter.getInstance()
                    .build(RouterConstants.MeterTask_MeterList)
                    .withInt("type", 1)
                    .navigation()
            }
            R.id.main_midmenu_datasyn -> {
                // 数据同步
                ARouter.getInstance().build(RouterConstants.DataAsynch_index).navigation()
            }
            R.id.main_bottommenu_statistics -> {
                // 查询统计
            }
        }
    }

    override fun onBackPressed() {
        if (System.currentTimeMillis() - viewModel.getfirstTimeValue() > 2000) {
            toast("再按一次退出程序")
            viewModel.setfirstTimeValue(System.currentTimeMillis())
        } else {
            AndActivityUtils.instance.clearActivity()
        }
    }

    override fun processHandlerMsg(msg: Message) {
    }
}